<?php
include('../class/class_connect.php');
include('class/class_mobilepage.php');
include('../class/class_comments.php');
include('../class/abstract/class_paginator.php');
include('../class/class_address.php');
include('../class/class_workdays.php');
include('../class/class_rating.php');
include('../class/city_rus.php');
include('../class/class_checkGetData.php');
$aCheck=new checkGetData('m');
if($_GET['city'])
{
	$aCheck->checkCity($_GET['city']);
}
session_start();
$aComment=new comments('m', $_GET['city'], $_GET['id']);
$aComment->addComment();
class aFirmPage extends page
{
	var $row=array();
	var $cityRus;
	function __construct()
	{
		$aConnect=new connect('m');
		if($_GET['city'])$this->row=mysql_fetch_array($aConnect->select_all($_GET['city'], ''));
		$this->cityRus=new city_rus_class();
		parent::__construct();
	}
	function title()
	{
		echo 'Торговые центры '.$this->cityRus->city_rus_im($_GET['city']);
	}
	function maincontent()
	{
		echo ('
		<link rel="stylesheet" type="text/css" href="http://pro-gorod.com/style/rating2060.css" />
		<link rel="stylesheet" type="text/css" href="http://pro-gorod.com/style/comments.css" />
		');
		if(!$_GET['city'])
		{
			echo '<center><h1>Выберите город!</h1></center>';
		}
		else
		{
			$wdStyle='';
			$selected='';
			if($_POST['filter']=='byWorkdays')
			{
				$wdStyle='style="display: block;"';
				$selected='selected';
			}

			$wdRus=array(
					'mon'=>'пн',
					'tue'=>'вт',
					'wed'=>'ср',
					'thi'=>'чт',
					'fri'=>'пт',
					'sat'=>'сб',
					'sun'=>'вс'
				);
			echo ('
			<div class="route">
				|Торговые центры|
			</div>
			<script type="text/javascript" src="http://pro-gorod.com/scripts/subdivFilter.js">
			</script>
			<link rel="stylesheet" type="text/css" href="http://pro-gorod.com/style/subdivFilter.css" />
			<div class="filter">
				<form name="filter" action="" method="post">
					<select size="1" name="filter" class="chooseFilter">
		  				<option id="byRating" value="byRating" selected>По рейтингу</option>
		  				<option id="byWorkdays" value="byWorkdays" '.$selected.'>По режиму работы</option>
					</select>
			');
			if($_POST['filter']=='byWorkdays')
				echo ('
				<input id="filterBut1" style="display: none;" class="button button-blue" type="submit" value="Показать"></input>
				');
			echo ('
				<div class="filterOptions">
					<div class="wdfilter" '.$wdStyle.'>
						<select size="1" name="weekday">
						');
						foreach($wdRus as $eng=>$rus)
						{
							$selected='';
							if($_POST['weekday']==$eng)
								$selected='selected';
							elseif($eng==strtolower(substr(date('l'), 0, 3)))
								$selected='selected';
							echo ('
			  				<option value="'.$eng.'" '.$selected.'>'.$rus.'</option>
			  				');
			  			}
			  			echo ('
						</select>
						минимум до:
						<select size="1" name="worktime">
			  			');
			  			$sel=false;
			  			if(!$_POST['workdays'])
			  			{
			  				$nearestHour=date('G')+1;
						}
						for($i=0; $i<24; $i++)
						{
							$selected='';
							$hour=$i;
							if($i<10)$hour='0'.$i;
							if($_POST['worktime']==$hour)
							{
								$selected='selected';
								$sel=true;
							}
							if(!$sel && $hour==$nearestHour)$selected='selected';
							echo ('
			  				<option value="'.$hour.'" '.$selected.'>'.$hour.'</option>
			  				');
			  			}
			  			echo ('
						</select>
						<input type="submit" id="filterBut" value="Показать" class="button button-blue">
					</div>
				</div>
				</form>
			</div>
			');
			$aMallsList=new mallsList();
		}
	}
}
class mallsList extends paginator
{
	var $mallsNum;
	function __construct()
	{
		parent::__construct(7);
	}
	function countRows()
	{
		$aConnect=new connect('m');
		$this->mallsNum=mysql_num_rows($aConnect->select_all($_GET['city'], "WHERE status='0'"));
		return $this->mallsNum;
	}
	function pageContent()
	{
		$like='';
		$like1='';
		if(isset($_POST['filter']))
		{
			if($_POST['filter']=='byWorkdays')
			{
				$time=$_POST['worktime'];
				$wd=$_POST['weekday'];
				if($time>10)
				{
					for($i=$time; $i<24; $i++)
					{
						$time=$i;
						if($i<10&&$i>0)$time='0'.$i;
						$like[]="workdays LIKE '%notevery~%".$wd."&%-".$time.":%&%'";
						$like1[]="workdays LIKE '%alldays~%-".$time.":%'";
					}
					for($i=0; $i<11; $i++)
					{
						$time=$i;
						if($i<10&&$i>0)$time='0'.$i;
						$like[]="workdays LIKE '%notevery~%".$wd."&%-".$time.":%&%'";
						$like1[]="workdays LIKE '%alldays~%-".$time.":%'";
					}
				}
				else
				{
					for($i=$time; $i<11; $i++)
					{
						$time=$i;
						if($i<10&&$i>0)$time='0'.$i;
						$like[]="workdays LIKE '%notevery~%".$wd."&%-".$time.":%&%'";
						$like1[]="workdays LIKE '%alldays~%-".$time.":%'";
					}
				}
				if($like)$like="AND (".implode(' || ', $like)." || ".implode(' || ', $like1)." || address LIKE '%^24%')";
			}
		}
		$aWorkdays=new workdays();
		echo ('
			<link rel="stylesheet" type="text/css" href="style/subdiv.css" />
			');
		if(!$this->mallsNum)echo '<center><h2>НИЧЕГО НЕ НАЙДЕНО<h2></center>';
		$aConnect=new connect('m');

		$res=$aConnect->select_all($_GET['city'], "WHERE status='0' ".$like." ORDER BY rating DESC LIMIT ".$this->lim.", ".$this->limit."");
		while($this->row=mysql_fetch_array($res))
		{
			$logo="";
			$logo='http://pro-gorod.com/pictures/mallspics/'.$_GET['city'].'/'.$this->row['id'].'.jpg';
			echo ('
			<div class="subdivFirm">
				<div class="nameShort" align="left">
					<div class="subdivFirmsName">
						<h4><a href="malls.php?city='.$_GET['city'].'&id='.$this->row['id'].'">'.$this->row['name'].'</a></h4>
					</div>
					<div class="subdivFirmsShort">
						'.$this->row['short'].'
					</div>
				</div>
				<table>
					<tr>
						<td width="350">

							<a href="malls.php?city='.$_GET['city'].'&id='.$this->row['id'].'"><img class="subdivPic"
							src="'.$logo.'" title="'.$this->row['name'].'""></a>
				');
							$aFirmRating=new rating('m');
							$aFirmRating->echo_rating(0, $this->row['rating'], $this->row['votes']);
							$aConnect=new connect('mc');
							$commentsNum=mysql_num_rows($aConnect->select_all($_GET['city'], "WHERE m_id='".$this->row['id']."'"));
				echo ('
							<a class="comsamount" href="comments.php?city='.$_GET['city'].'&id='.$this->row['id'].'&obj=malls"><font color="grey">отзывов:</font> '.$commentsNum.'</a>
						</td>
						<td class="subdivInfo">
							<table border="0" align="left">
							<tr>
								<td class="namesCol">
									Адрес:
								</td>
								<td width="250">
									 '.$this->row['address'].'
								</td>
							</tr>
							<tr>
								<td class="namesCol">
									Телефон:
								</td>
								<td>
								 '.$this->row['phone'].'
								</td>
							</tr>
							<tr>
								<td class="namesCol">
									Часы работы:
								</td>
								<td>
								');
									$aWorkdays->showWorkdays($this->row['workdays']);
								echo ('
								</td>
							</tr>
                       		<tr>
                       			<td class="namesCol">
                       				сайт:
                       			</td>
                       			<td>
                       		');
                       		if($this->row['link'])
                       			echo '<a href="http//:'.$this->row['link'].'">www.'.$this->row['link'].'</a>';
                       		else
                       			echo ('не указан');
                       		echo ('
                       			</td>
                       		</tr>
                       		</table>
						</td>
					</tr>
				</table>
			</div>
			');
		}
	}
}
$aPage=new aFirmPage();

?>